<%--
  Created by IntelliJ IDEA.
  User: aaa
  Date: 2024/6/27
  Time: 6:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
  <title>用户注册</title>
<style>
  .content{
    border: black solid 5px;
    width: 1100px;
    height: 600px;
    margin-top: -280px;
    margin-left: 230px;
    color: grey;
    font-size: 50px;
  }
  .Add{
    border: black solid 5px;
    width: 500px;
    height: 500px;
    margin-top: -580px;
    margin-left: 500px;
    color: mediumslateblue;
    font-size: 25px;
  }
</style>
</head>
<body>
<div class="content">

</div>
<div class="Add">
<form action="ManagerServlet?action=addThisPerson" method="post" onsubmit="return checkThis()">
  <center>
  <table>
    <tr>
      <td>姓名:</td>
      <td><input type="text" id="name" name="userName" required></td>
    </tr>
    <tr>
      <td>性别:</td>
      <td>
        <select id="gender" name="userSex" required>
          <option value="男">男</option>
          <option value="女">女</option>
        </select>
      </td>
    </tr>
    <tr>
      <td>出生日期:</td>
      <td><input type="date" id="userBirthday" name="userBirthday" required></td>
    </tr>
    <tr>
      <td>身份证号码:</td>
      <td><input type="number" id="id_card" name="userIdCard" required></td>
    </tr>
    <tr>
      <td>手机号码:</td>
      <td><input type="number" id="phone" name="userPhone" required></td>
    </tr>
    <tr>
      <td>角色:</td>
      <td>
        <select id="userIdentify" name="userIdentify" >
          <option id="a" value="0">学生</option>
          <option id="b" value="1">老师</option>
        </select>
      </td>
    </tr>
    <tr>
      <td>职务:</td>
      <td><input type="text" id="position" name="userOtherName" placeholder="某科老师/学生"  required></td>
    </tr>
    <tr>
      <td>密码:</td>
      <td><input type="password" id="password" name="userPassword" required></td>
    </tr>
    <tr>
      <td>再次输入密码:</td>
      <td><input type="password" id="confirm_password" name="confirm_password" required></td>
    </tr>
    <tr>
      <td colspan="2" style="text-align: center;">
        <button type="submit">添加</button>
      </td>
    </tr>
  </table>
  <div id="error" style="color: red;"></div>
  </center>
</form>

</div>
</body>
<script>
  function checkThis() {
    var name = document.getElementById("name").value;
    var gender = document.getElementById("gender").value;
    var dob = document.getElementById("dob").value;
    var idCard = document.getElementById("id_card").value;
    var phone = document.getElementById("phone").value;
    var role = document.getElementById("role").value;
    var position = document.getElementById("position").value;
    var password = document.getElementById("password").value;
    var confirmPassword = document.getElementById("confirm_password").value;

    if (name.trim() == "" || name == null) {
      document.getElementById("error").innerHTML = "姓名不能为空";
      return false;
    }

    if (gender.trim() == "" || gender == null) {
      document.getElementById("error").innerHTML = "性别不能为空";
      return false;
    }

    if (dob.trim() == "" || dob == null) {
      document.getElementById("error").innerHTML = "出生日期不能为空";
      return false;
    }

    if (idCard.trim() == "" || idCard == null) {
      document.getElementById("error").innerHTML = "身份证号码不能为空";
      return false;
    }

    if (phone.trim() == "" || phone == null) {
      document.getElementById("error").innerHTML = "手机号码不能为空";
      return false;
    }

    if (role.trim() == "" || role == null) {
      document.getElementById("error").innerHTML = "角色不能为空";
      return false;
    }

    if (position.trim() == "" || position == null) {
      document.getElementById("error").innerHTML = "职务不能为空";
      return false;
    }

    if (password.trim() == "" || password == null) {
      document.getElementById("error").innerHTML = "密码不能为空";
      return false;
    }

    if (confirmPassword.trim() == "" || confirmPassword == null) {
      document.getElementById("error").innerHTML = "确认密码不能为空";
      return false;
    }

    var idCardReg = /(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    var phoneReg = /(^\d{11}$)/;

    if (!idCardReg.test(idCard)) {
      document.getElementById("error").innerHTML = "身份证输入不合法";
      return false;
    }

    if (!phoneReg.test(phone)) {
      document.getElementById("error").innerHTML = "手机号输入不合法";
      return false;
    }

    if (password !== confirmPassword) {
      document.getElementById("error").innerHTML = "两次密码不相同";
      return false;
    }

    return true;
  }
</script>
</html>